#pragma once

#include "sys/conv.h"

SYS_BEGIN()

namespace detail{
	//string conv
	template<>
	struct a2b_<sys::vstring<char>,const char*>
	{
		static sys::vstring<char> conv(const char *s)
		{
			return sys::vstring<char>(s); 
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,char*>
	{
		static sys::vstring<char> conv(char *s)
		{
			return sys::vstring<char>(s); 
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,std::string>
	{
		static sys::vstring<char> conv(std::string s)
		{
			return sys::vstring<char>(s.c_str(), static_cast<ulong>(s.size())); 
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,const wchar_t*>
	{
		static sys::vstring<char> conv(const wchar_t* ws)
		{
			return sys::WSTR2vstring(ws);
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,wchar_t*>
	{
		static sys::vstring<char> conv(wchar_t* ws)
		{
			return sys::WSTR2vstring(ws);
		}
	};


	//number conv
	template<>
	struct a2b_<sys::vstring<char>,int32>
	{
		static sys::vstring<char> conv(int32 n)
		{
			sys::vstring<char> buf(16,' ');
			buf.resize(sprintf_s(buf.begin(), 16,"%d", n)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,unsigned>
	{
		static sys::vstring<char> conv(unsigned u)
		{
			sys::vstring<char> buf(16,' ');
			buf.resize(sprintf_s(buf.begin(), 16,"%u", u)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,long>
	{
		static sys::vstring<char> conv(long l)
		{ 
			sys::vstring<char> buf(16,' ');
			buf.resize(sprintf_s(buf.begin(), 16,"%ld", l)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,unsigned long>
	{
		static sys::vstring<char> conv(unsigned long ul)
		{ 
			sys::vstring<char> buf(16,' ');
			buf.resize(sprintf_s(buf.begin(), 16, "%lu", ul)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,real4>
	{
		static sys::vstring<char> conv(real4 f)
		{ 
			sys::vstring<char> buf(16,' ');
			buf.resize(sprintf_s(buf.begin(), 16, "%lf",static_cast<real8>(f))); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<char>,real8>
	{
		static sys::vstring<char> conv(real8 d)
		{ 
			sys::vstring<char> buf(16,' ');
			buf.resize(sprintf_s(buf.begin(), 16, "%lf", d)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,const wchar_t*>
	{
		//string conv
		static sys::vstring<vchar> conv(const wchar_t* ws)
		{
			return sys::vstring<vchar>((const vchar*)ws); 
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,wchar_t*>
	{
		//string conv
		static sys::vstring<vchar> conv(wchar_t* ws)
		{
			return sys::vstring<vchar>((const vchar*)ws); 
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,String>
	{
		static sys::vstring<vchar> conv(String ws)
		{
			return sys::vstring<vchar>((const vchar*)ws.c_str()); 
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,const char*>
	{
		static sys::vstring<vchar> conv(const char* s)
		{
			return sys::STR2vwstring(s);
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,char*>
	{
		static sys::vstring<vchar> conv(char* s)
		{
			return sys::STR2vwstring(s);
		}
	};


	//number conv
	template<>
	struct a2b_<sys::vstring<vchar>,int32>
	{
		static sys::vstring<vchar> conv(int32 n)
		{
			sys::vstring<vchar> buf(16,L' ');
			buf.resize(swprintf_s((LPWSTR)buf.begin(), 16,L"%d", n)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,unsigned>
	{
		static sys::vstring<vchar> conv(unsigned u)
		{
			sys::vstring<vchar> buf(16,L' ');
			buf.resize(swprintf_s((LPWSTR)buf.begin(), 16,L"%u", u)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,long>
	{
		static sys::vstring<vchar> conv(long l)
		{ 
			sys::vstring<vchar> buf(16,L' ');
			buf.resize(swprintf_s((LPWSTR)buf.begin(), 16,L"%ld", l)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,unsigned long>
	{
		static sys::vstring<vchar> conv(unsigned long ul)
		{ 
			sys::vstring<vchar> buf(16,L' ');
			buf.resize(swprintf_s((LPWSTR)buf.begin(), 16, L"%lu", ul)); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,real4>
	{
		static sys::vstring<vchar> conv(real4 f)
		{ 
			sys::vstring<vchar> buf(16,L' ');
			buf.resize(swprintf_s((LPWSTR)buf.begin(), 16, L"%lf",static_cast<real8>(f))); 
			return buf;
		}
	};

	template<>
	struct a2b_<sys::vstring<vchar>,real8>
	{
		static sys::vstring<vchar> conv(real8 d)
		{ 
			sys::vstring<vchar> buf(16,L' ');
			buf.resize(swprintf_s((LPWSTR)buf.begin(), 16, L"%lf", d)); 
			return buf;
		}
	};
}

SYS_END()